<template>
  <div class="shopl">
    <!-- <go-back></go-back> -->
    <div class="sclass">
      <ul class="sclass1">
        <!-- <li class="sclassa" v-for="(item,i) in guid" :key="i">
        {{item.name}}
      </li> -->
        <li :class="{ active: index == 1 }" @click="index = 1">热门推荐</li>
        <li :class="{ active: index == 2 }" @click="index = 2">上新推荐</li>
        <li :class="{ active: index == 3 }" @click="index = 3">所有商品</li>
      </ul>
    </div>
    <ul class="shopa1" v-show="index == 1">
      <!-- 进入商品详情detail，router是声明式,动态路由拼接
      ，改变index.js -->
      <!-- <li v-for="(item, i) in guid" :key="i">
        <router-link :to="'./detail/' + item.id">
          <img :src="item.img" alt="" />
          <div class="shopl1">
            <span class="shopl1a">{{ item.name }}</span>
            <span class="shopl1b">{{ item.price }}</span>
            <span class="shopl1c">{{ item.price1 }}</span>
            <div class="shopl1d">{{ item.go }}</div>
          </div>
        </router-link>
      </li> -->

      <!--  编程式样路由拼接 -->
      <li v-for="item in shop1" :key="item.id" @click="goDetail(item.id)">
        <img :src="'http://localhost:3000' + item.img" alt="" />
        <div class="shopl1">
          <span class="shopl1a">{{ item.goodsname }}</span>
          <span class="shopl1b">{{ item.market_price }}</span>
          <span class="shopl1c">{{ item.price }}</span>
          <div class="shopl1d">立即抢购</div>
        </div>
      </li>
    </ul>

    <ul class="shopa1" v-show="index == 2">
      <li v-for="item in shop2" :key="item.id" @click="goDetail(item.id)">
        <img :src="'http://localhost:3000' + item.img" alt="" />
        <div class="shopl1">
          <span class="shopl1a">{{ item.goodsname }}</span>
          <span class="shopl1b">{{ item.market_price }}</span>
          <span class="shopl1c">{{ item.price }}</span>
          <div class="shopl1d">立即抢购</div>
        </div>
      </li>
    </ul>

    <ul class="shopa1" v-show="index == 3">
      <li v-for="item in shop3" :key="item.id" @click="goDetail(item.id)">
        <img :src="'http://localhost:3000' + item.img" alt="" />
        <div class="shopl1">
          <span class="shopl1a">{{ item.goodsname }}</span>
          <span class="shopl1b">{{ item.market_price }}</span>
          <span class="shopl1c">{{ item.price }}</span>
          <div class="shopl1d">立即抢购</div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import { getHomeGoods, getgoodsinfo } from "../util/request/api";

export default {
  data() {
    return {
      index: 1,
      shop1: [],
      shop2: [],
      shop3: [],

      //
    };
  },
  methods: {
    // 编程时导航常用？？
    goDetail(id) {
      getgoodsinfo({ id }).then((res) => {
        if (res.code == 200) {
          console.log(res, "shil");
        }
      });
      // this.$router 是路由实例化配置对象
      console.log(this.$router, "this");
      // push会留下历史记录，点击浏览器后退会回到上一个页面
      this.$router.push("./detail/" + id);
      // replace，会替换当前历史记录，感觉不会用它
      // this.$router.replace('./detail')
    },
  },
  mounted() {
    // this.$axios.get('/api/gethortgoods')
    getHomeGoods().then((res) => {
      console.log(res, "shopl");
      // 本应该有个data，但因为设置的全库拦截，token，所以去掉data
      console.log(res,'res')
      if (res.code == 200) {
        this.shop1 = res.list[0].content;
        this.shop2 = res.list[1].content;
        this.shop3 = res.list[2].content;
      }
    });
  },
};
</script>
<style>
.shopl {
  width: 5.72rem;
  margin: 0 auto;
  margin-top: 0.16rem;
}
.shopl .shopa1 {
  display: flex;
  flex-direction: column;
}
.shopl .shopa1 li {
  width: 5.72rem;
  height: 2.72rem;
  border: 0.02rem #ddd solid;
  /* background: chartreuse; */
}
.shopl .shopa1 li img {
  width: 1.84rem;
  height: 2rem;
  margin-top: 0.2rem;
  float: left;
}
.shopl .shopa1 li .shopl1 {
  height: 2.72rem;
  font-size: 0.23rem;
  font-weight: 900;
  float: revert;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding-left: 0.2rem;
}
.shopl .shopa1 li .shopl1 .shopl1b {
  color: red;
}
.shopl .shopa1 li .shopl1 .shopl1c {
  color: #ccc;
  text-decoration: line-through;
}
.shopl .shopa1 li .shopl1 .shopl1d {
  width: 1.36rem;
  height: 0.46rem;
  color: white;
  background: #f2a83b;
  text-align: center;
  line-height: 0.46rem;
  border-radius: 0.05rem;
}

.sclass {
  margin: 0 auto;
  width: 6.5rem;
  font-size: 0.22rem;
  line-height: 0.58rem;
  text-align: center;
  position: relative;
  left: -0.4rem;
  margin-bottom: 0.3rem;
}
.sclass li {
  width: 33%;
}
.sclass li {
  background: #26b193;
  border-radius: 0.05rem;
}
.sclass1 {
  display: flex;
}
.active {
  color: #ccc !important;
  background: #f2a83b !important;
  border-radius: 0.3rem;
}
</style>